/*********************************************************************************
  *FileName:  nsuc16xx_exit.c
  *Version:   V1.0
  *Date:      2023-09-21
****************************************Includes***********************************/
#include "nsuc16xx_exit.h"

/***************************************Variables***********************************/

/***************************************Functions***********************************/

/**
 * @brief  Initializes the EXTI peripheral according to the specified
 *         parameters in the EXTI_InitStruct.
 * @param  EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure
 *         that contains the configuration information for the EXTI peripheral.
 * @retval None
 */
void EXTI_Init(EXTI_InitTypeDef *EXTI_InitStruct)
{
    if (EXTI_InitStruct->EXTI_LineCmd != DISABLE)
    {
        GPIO->ICR &= ~((uint32_t)0x3 << ((uint32_t)((uint32_t)EXTI_InitStruct->EXTI_Source & (uint32_t)0x0F) * 2));
        GPIO->ICR |= ((uint32_t)EXTI_InitStruct->EXTI_Trigger
                      << ((uint32_t)((uint32_t)EXTI_InitStruct->EXTI_Source & (uint32_t)0x0F) * 2));
        GPIO->IEN |= ((uint32_t)0x1 << (uint32_t)((uint32_t)EXTI_InitStruct->EXTI_Source & (uint32_t)0x0F));
    }
    else
    {
        GPIO->IEN &= ~((uint32_t)0x1 << (uint32_t)((uint32_t)EXTI_InitStruct->EXTI_Source & (uint32_t)0x0F));
    }
}

/**
 * @brief  Gets the GPIO external interrupt status bit.
 * @param  EXTI_Line: external interrupt source.
 * @retval Whether an external interrupt is triggered
 */
ITStatus EXTI_GetITStatus(uint32_t EXTI_Line)
{
    ITStatus bitstatus = RESET;

    if ((GPIO->IPND & EXTI_Line) != (uint32_t)RESET)
    {
        bitstatus = SET;
    }
    else
    {
        bitstatus = RESET;
    }
    return bitstatus;
}

/**
 * @brief  Clears the external interrupt flag bit.
 * @param  EXTI_Line: external interrupt source.
 * @retval None.
 */
void EXTI_ClearITPendingBit(uint32_t EXTI_Line)
{
    GPIO->EIPND = EXTI_Line;
}

/***************************************END OF FILE*********************************/
